package zhtt.java2.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import zhtt.java2.entity.Spitter;
import zhtt.java2.repository.SpitterRepository;

import java.util.List;

/**
 * Created by zhaott on 2018/1/31.
 */
@Service
public class SpitterService {

    @Autowired
    private SpitterRepository spitterRepository;

    public void init(){
        List list=queryForList("admin");
        if(list.size()==0){
            Spitter spitter=new Spitter();
            spitter.setFirstName("admin");
            spitter.setLastName("admin");
            spitter.setEmail("admin");
            spitter.setUsername("admin");
            spitter.setPassword("admin");
            save(spitter);
        }
        System.out.println(list);
    }

    public void save(Spitter spitter){
        spitterRepository.save(spitter);
    }

    public Spitter findByUsername(String username){
        Spitter spitter=spitterRepository.findByUsername(username);
        return spitter;
    }

    public List queryForList(String username){
        List spitter=spitterRepository.queryForList();
        return spitter;
    }
}
